import matplotlib.pyplot as plt
import seaborn as sns
import  numpy as np
import cv2
plt.rcParams['font.sans-serif'] = ['SimHei']  # 中文字体设置-黑体
plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题
sns.set(font='SimHei',font_scale=0.8)  # 解决Seaborn中文显示问题

def plotbar(xlist,ylist,title,xlabel,ylabel,isrotate = False):
    savedir ='./infocache/imgs'
    fig = sns.barplot(x=xlist, y=ylist, ci=68)
    rects = fig.patches

    # Make some labels.
    fig.set_title(title)

    fig.set_xlabel(xlabel)

    fig.set_ylabel(ylabel)

    for rect, label in zip(rects, ylist):
        print(label)
        height = rect.get_height()
        fig.text(rect.get_x() + rect.get_width() / 2, height + 5, label,
                ha='center', va='bottom')
    if isrotate:
        for tick in fig.get_xticklabels():
            tick.set_rotation(45)
    name = savedir+'//'+title+'.jpg'
    plt.savefig(name)

    plt.show()
def plothistogram(data,xlabel,ylabel,title):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    # 第二个参数是柱子宽一些还是窄一些，越大越窄越密
    ax.hist(data, 20, density=1, histtype='bar', facecolor='yellowgreen', alpha=0.75)
    ##pdf概率分布图，一万个数落在某个区间内的数有多少个
    ax.set_title(title)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    # cdf累计概率函数，cumulative累计。比如需要统计小于5的数的概率
    fig.subplots_adjust(hspace=0.4)
    plt.show()
